﻿<%@ Page Title="主页" Language="C#" AutoEventWireup="true" CodeBehind="ProjectTimeGraph.aspx.cs"
    Inherits="WebApplication.ProjectTimeGraph" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>时间图</title>
    <script src="../scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
        .AreaTitle
        {
            border-bottom: 1px solid black;
            width: 100px;
        }
        .TimeColumn
        {
            width: 100px;
        }
        .Map
        {
            border: 1px solid black;
            border-collapse: collapse;
        }
        .Map .Node
        {
            border: 1px solid black;
            border-collapse: collapse;
            margin: 10px 10px;
            padding: 10px;
        }
        .Map .NameTd
        {
            width: 30px;
            text-align: center;
        }
        .Map .NameTd .Name
        {
            width: 20px;
            padding: 5px;
        }
        .Map td
        {
            height: 50px;
            text-align: center;
        }
        .Node
        {
            color: White;
            border: 1px solid gray;
            height: 40px;
            padding: 2px 4px;
            border-radius: 5px; /*box-shadow: 5px 5px 5px #888888;*/ /* opacity: 0.8;
            filter: alpha(opacity=80);*/
            position: absolute;
            overflow: hidden;
            cursor: pointer;
        }
        .Node span
        {
            display: block;
            height: 19px;
            line-height: 19px;
            border-bottom: 1px solid lightgray;
            text-align: center;
        }
        .Working span
        {
            color: white;
        }
    </style>
    <script type="text/javascript">
    var nodes=<%=MapData %>;
    var HEIGHT=53;
    </script>
    <script type="text/javascript">
        var container = null;
        $(function () {
            if ($(".Map").width() < $(window).width() - 2) {
                $(".Map").width($(window).width() - 2)
            }
            container = $("body"); drawLine();
        });
        var x, y;
        function drawLine() {
            var th = $("th").first();
            x = th.offset().left + th.outerWidth();
            y = th.offset().top + th.outerHeight();
            for (var i = 0; i < nodes.length; i++) {
                var column = $("#" + nodes[i].BeginDateID);
                var days = parseInt(column.attr("days"));
                var ratio = column.width() / days;
                var left = column.offset().left + ratio * nodes[i].BeginDayIndex;
                var top = y + nodes[i].RowIndex * HEIGHT + 3;

                column = $("#" + nodes[i].EndDateID);
                var days = parseInt(column.attr("days"));
                var ratio = column.width() / days;
                var right = column.offset().left + ratio * nodes[i].EndDayIndex;
                var width = right - left;
                if (width < 60) { width = 60; }
                container.append("<div onclick='openPointDetails(\"" + nodes[i].ID + "\")' title='" + nodes[i].Content + "' style='left:" + left + "px;top:" + top + "px;width:" + width + "px' class='Node " + nodes[i].StatusString + "'><span>" + nodes[i].Days + "天</span><div>" + nodes[i].Content + "</div></div>");
            }
            var now = new Date();
            var year = now.getFullYear().toString();
            var month = now.getMonth() + 1;
            var day = now.getDate();
            if (month < 10) { month = "0" + month; }
            var column = $("#" + year + "_" + month);
            if (!column) { return; }
            var days = parseInt(column.attr("days"));
            var ratio = column.width() / days;
            var left = column.offset().left + ratio * day;
            var top = column.offset().top;
            var height = $(".Map").height();
            container.append("<div id='currentDate' style='color:red;left:" + (left - 40) + "px;top:" + (top - 20) + "px;position:absolute;z-index:999'>" + year + "-" + month + "-" + day + "</div>");
            container.append("<div id='currentDateLine' style='width:1px;background:red;position:absolute;left:" + left + "px;top:" + top + "px;height:" + height + "px;z-index:999'></div>");
        }
    </script>
</head>
<body>
    <div id="TopHeader" style="width: 100%; background: white; position: absolute; z-index: 998">
        <script type="text/javascript">            writeStatusHtml();</script>
    </div>
    <div id="TableHeader" style="background: white; position: absolute; z-index: 998;
        top: 34px;">
    </div>
    <div id="TableRows" style="background: white; position: absolute; z-index: 997;
        top: 59px;">
    </div>
    <script type="text/javascript">        writeStatusHtml();</script>
    <div id="MapContainer" runat="server" clientidmode="Static">
    </div>
</body>
<script type="text/javascript">
    mini.parse();
</script>
<script type="text/javascript">
    var currentDateLineHeight = 0;
    $(function () {
        currentDateLineHeight = $("#currentDateLine").height();
        var source = $(".Map").children().eq(0).children().eq(0);
        var rows = $(".Map tr");

        $("#TableHeader").html("<table border='1' class='Map' style='background:#F2EFE8;width:" + ($(".Map").width() + 2) + "px'>" + source.html() + "</table>");
        var newColumn = $("#TableHeader th");

        var TableRowsHtml = "<table border='1' class='Map' style='background:#F2EFE8;'>";
        for (var i = 1; i < rows.length; i++) {
            var html = rows.eq(i).children().eq(0).html();
            if (html != "") {
                TableRowsHtml += "<tr><td style='width:" + (rows.eq(i).children().eq(0).width() + 1) + "px;height:" + (rows.eq(i).children().eq(0).height() + 1) + "px'>" + html + "</td></tr>";
            }
        }
        TableRowsHtml += "</table>";
        $("#TableRows").html(TableRowsHtml);
    });

    $(window).scroll(function (e) {
        $("#TopHeader").offset({ top: $(window).scrollTop(), left: $(window).scrollLeft() })
        $("#TableHeader").offset({ top: $(window).scrollTop() + 34, left: $("#TableHeader").offset().left })
        $("#currentDate").offset({ top: $(window).scrollTop() + 14, left: $("#currentDate").offset().left })
        $("#currentDateLine").height(currentDateLineHeight - $(window).scrollTop());
        $("#currentDateLine").offset({ top: $(window).scrollTop() + 34, left: $("#currentDateLine").offset().left })
        $("#TableRows").offset({ top: $("#TableRows").offset().top, left: $(window).scrollLeft() })
    });
</script>
<script type="text/javascript">
    function openPointDetails(id) {
        mini.open({
            url: "/Business/NodeDetails.aspx?id=" + id,
            title: "节点明细", width: 900, height: 640,
            ondestroy: function (action) {
                if (action == "ok") {
                    mini.get("rootPanel").loading();
                    var iframe = this.getIFrameEl();
                    var datas = iframe.contentWindow.GetData();
                    var accounts = new Array();
                    for (var i = 0; i < datas.length; i++) {
                        accounts.push(datas[i].Account);
                    }
                }
            }
        });
    }
</script>
</html>
